import java.util.Scanner;
import java.util.Random;

public class Lab_01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        int correctCount = 0;
        int totalCount = 50;
        
        System.out.println("欢迎参加100以内加减法口算练习！");
        System.out.println("请在每道题目后输入你的答案，按Enter键确认。");
        System.out.println("开始答题：\n");
        
        for (int i = 1; i <= totalCount; i++) {
            // 生成两个100以内的随机数
            int num1 = random.nextInt(100);
            int num2 = random.nextInt(100);
            
            // 随机选择加法或减法
            boolean isAddition = random.nextBoolean();
            int correctAnswer;
            String operator;
            
            if (isAddition) {
                // 加法
                operator = "+";
                correctAnswer = num1 + num2;
            } else {
                // 减法，确保结果非负
                operator = "-";
                if (num1 < num2) {
                    // 交换两个数，确保被减数大于减数
                    int temp = num1;
                    num1 = num2;
                    num2 = temp;
                }
                correctAnswer = num1 - num2;
            }
            
            // 显示题目并获取用户答案
            System.out.print("第" + i + "题: " + num1 + " " + operator + " " + num2 + " = ");
            int userAnswer = scanner.nextInt();
            
            // 判断答案是否正确
            if (userAnswer == correctAnswer) {
                System.out.println("回答正确！");
                correctCount++;
            } else {
                System.out.println("回答错误！正确答案是: " + correctAnswer);
            }
            System.out.println();
        }
        
        // 输出统计结果
        System.out.println("练习完成！");
        System.out.println("总共" + totalCount + "道题，答对" + correctCount + "道题。");
        double accuracy = (double) correctCount / totalCount * 100;
        System.out.printf("正确率：%.1f%%\n", accuracy);
        
        // 根据正确率给出评价
        if (accuracy >= 90) {
            System.out.println("太棒了！你的计算能力非常出色！");
        } else if (accuracy >= 80) {
            System.out.println("很好！继续努力！");
        } else if (accuracy >= 60) {
            System.out.println("还不错，多加练习会更好！");
        } else {
            System.out.println("需要更多练习，加油！");
        }
        
        scanner.close();
    }
}